<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <erp-customer-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></erp-customer-form>


    <!-- 自定义底部按钮 -->
    <template slot="footer">
      <div class="modal-footer-center">
        <a-button @click="handleCancel">关闭</a-button>
        <a-button v-if="!disableSubmit" type="primary" @click="handleOk">确定</a-button>
      </div>
    </template>
  </j-modal>
</template>

<script>

  import ErpCustomerForm from './ErpCustomerForm'
  export default {
    name: 'ErpCustomerModal',
    components: {
      ErpCustomerForm
    },
    data () {
      return {
        title:'',
        width:1600,
        visible: false,
        disableSubmit: false
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>

<style scoped>
/* 模态框底部按钮居中 */
.modal-footer-center {
  text-align: center;
  width: 100%;
}

/* 使用深度选择器修改子组件中的按钮样式 */
/deep/ .erp-customer-form .form-button-container,
/deep/ .erp-customer-form .ant-form-item:last-child .ant-form-item-control-wrapper {
  text-align: center !important;
}
</style>